/*
 * Copyright (c) GoKeep by gokeep.org. 2022-2023. All rights reserved
 */
package org.gokeep.application.rest;

import com.github.benmanes.caffeine.cache.Cache;
import jakarta.annotation.Resource;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.gokeep.common.util.JsonUtil;
import org.gokeep.common.util.UserContext;
import org.gokeep.common.dto.UserContextInfo;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/debug")
public class DebugApi {
    @Resource
    private Cache<String, Object> cache;
    /**
     * 获取缓存中的所有对象
     * @return
     */
    @GetMapping("/cache")
    public String showCache() {
        return JsonUtil.toJson(cache.asMap());
    }

    /**
     * 获取当前用户上下文
     * @return
     */
    @GetMapping("/context")
    public UserContextInfo getUserContext() {
        UserContextInfo userContext =  UserContext.getUserContextInfo();
        log.info("Context is : {}", userContext);
        return userContext;
    }

    @Data
    static class HazelcastMapDto{
        private String cacheKey;
        private String key;
        private String value;
    }
}
